package ext.tianma.project2.APQP.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.dom4j.DocumentException;

import wt.util.WTProperties;

/**
 * 资料外发基本配置文件
 * @author xucr
 */
public class APQPConfig {

	private static String FILEPATH ;
	private static File file ;
	private static Long lastModifyTime = 0L;
	private static String THOME ;
	
	private static Properties prop = new Properties();
	private static final String LIBRARYNAME = "libraryName";//指定存储库下的外发资料，没有【下一步】操作
	
	static {
		try {
			WTProperties wtproperties = WTProperties.getLocalProperties();
			THOME = wtproperties.getProperty("wt.codebase.location");
			//ext\tianma\project2\APQP\config\APQPConfig.properties
			FILEPATH = THOME + File.separator + "ext" +
					File.separator + "tianma" + File.separator + "project2" + File.separator +
					"APQP" + File.separator + "config" + File.separator + "APQPConfig.properties";
			
			file = new File(FILEPATH);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static String getKey(String key) throws DocumentException, IOException {
		load();
		
		return prop.getProperty(key);
	}
	
	private static Properties load() throws DocumentException, IOException {
		if(file.lastModified() > lastModifyTime) {
			prop.clear();
			InputStream ins = new FileInputStream(FILEPATH);
			if(null != ins) {
				InputStreamReader inputst = new InputStreamReader(ins, "UTF-8");
				prop.load(inputst);
			}
			lastModifyTime = file.lastModified();
		}
		return prop;
	}
}
